<?php

namespace addons\member\user\controller;

/**
 * 扫码支付
 * Class Sacn
 * @package addons\member\user\controller
 */
class Sacn extends \web\user\controller\AddonUserBase{
    
    public function index(){
        return $this->fetch();
    }
    
    public function loadList(){
        $keyword = $this->_get('keyword');
        $pay_type = $this->_get('pay_type');
        $status = $this->_get('status');
        $startDate = $this->_get('startDate');
        $endDate = $this->_get("endDate");
        $filter = '1=1';

        if($pay_type != ''){
            $filter .= ' and a.pay_type='.$pay_type;
        }
        if($status != ''){
            $filter .= ' and a.status='.$status;
        }
        if ($keyword != null) {
            $filter .= ' and b.username like \'%' . $keyword . '%\' or b.phone like \'%' . $keyword . '%\'';
        }
        if ($startDate != null && $endDate != null)
            $filter .= ' and (a.update_time >= \'' . $startDate . ' 00:00:00\' and a.update_time <= \'' . $endDate . ' 23:59:59\')';
        elseif ($startDate != null)
            $filter .= ' and (a.update_time >= \'' . $startDate . ' 00:00:00\')';
        elseif ($endDate != null)
            $filter .= ' and (a.update_time <= \'' . $endDate . ' 23:59:59\')';
        $m = new \addons\member\model\MemberSacn();
        $total = $m->getSacnTotal($filter);

        $fields = 'a.*,b.username';
        $rows = $m->getSacnList($this->getPageIndex(), $this->getPageSize(), $filter, $fields);
        $cny_amount = 0;
        $yuu_amount = 0;
        if($rows){
            foreach ($rows as $value){
                $cny_amount += $value['cny_amount'];
                $yuu_amount += $value['yuu_amount'];
            }
        }
        return $this->toTotalSacn($total, $rows, $cny_amount, $yuu_amount);
    }

}
